﻿// Copyright (C) 2012 Jeff Tanner <jeff00seattle@gmail.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 

using System;
using System.IO;
using System.Configuration;
using System.Diagnostics;
using Microsoft.Win32;

using WindowsAzure_REST;

namespace WindowsAzure_FileBackup_Common
{
    partial class Common
    {
        protected static RegistryKey WindowsAzureFileBackupRegistry
        {
            get
            {
                string subKey = String.Format("SOFTWARE\\{0}\\{1}", ConfigurationManager.AppSettings["RegistryRootName"], ConfigurationManager.AppSettings["RegistryAppName"]);
                Registry.LocalMachine.CreateSubKey(subKey);

                return Registry.LocalMachine.OpenSubKey(subKey, true);
            }
        }

        protected static StorageConnectionMode WindowsAzureConnectionModeRegistry
        {
            get
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                string connectionType = (string)myKey.GetValue("WindowsAzureConnectionMode");
                if (String.IsNullOrEmpty(connectionType))
                {
                    myKey.SetValue("WindowsAzureConnectionMode", StorageConnectionMode.Cloud.ToString(), RegistryValueKind.String);
                    return StorageConnectionMode.Cloud;
                }

                return (StorageConnectionMode)Enum.Parse(typeof(StorageConnectionMode), connectionType);
            }
            set
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                myKey.SetValue("WindowsAzureConnectionMode", value.ToString(), RegistryValueKind.String);
            }
        }

        protected static string WindowsAzureCloudStorageAccountNameRegistry
        {
            get
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                return (string)myKey.GetValue("WindowsAzureCloudStorageAccountName");
            }
            set
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                myKey.SetValue("WindowsAzureCloudStorageAccountName", value.ToString(), RegistryValueKind.String);
            }
        }

        protected static string WindowsAzureCloudStorageAccountKeyRegistry
        {
            get
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                return (string)myKey.GetValue("WindowsAzureCloudStorageAccountKey");
            }
            set
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                myKey.SetValue("WindowsAzureCloudStorageAccountKey", value.ToString(), RegistryValueKind.String);
            }
        }

        protected static string WindowsAzureStorageBlobContainerNameRegistry
        {
            get
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                return (string)myKey.GetValue("WindowsAzureStorageBlobContainerName");
            }
            set
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                myKey.SetValue("WindowsAzureStorageBlobContainerName", value.ToString(), RegistryValueKind.String);
            }
        }

        protected static string WindowsAzureFileBackupRootDirRegistry
        {
            get
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                return (string)myKey.GetValue("WindowsAzureFileBackupRootDir");
            }
            set
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                myKey.SetValue("WindowsAzureFileBackupRootDir", value.ToString(), RegistryValueKind.String);
            }
        }

        protected static string WindowsAzureFileRecoveryRootDirRegistry
        {
            get
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                return (string)myKey.GetValue("WindowsAzureFileRecoveryRootDir");
            }
            set
            {
                RegistryKey myKey = Common.WindowsAzureFileBackupRegistry;

                myKey.SetValue("WindowsAzureFileRecoveryRootDir", value.ToString(), RegistryValueKind.String);
            }
        }
    }
}
